package com.yuju.login.service.impl;


import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuju.common.core.dao.IBaseDao;
import com.yuju.common.core.service.AbstractBaseService;
import com.yuju.login.dao.IOwnerCustomDao;
import com.yuju.login.dao.entity.OwnerCustom;
import com.yuju.login.model.OwnerCustomModel;
import com.yuju.login.service.IOwnerCustomService;
import com.yuju.util.Utils;

/**
 * 类名：OwnerCustomServiceImpl  <br />
 *
 * 功能：
 *
 * @author : jiaokn <br />
 * @Date : 2017年11月24日 下午3:28:20  <br />
 * @version : 1.1 <br />
 */
@Service
public class OwnerCustomServiceImpl extends AbstractBaseService<OwnerCustomModel, OwnerCustom, String> implements IOwnerCustomService {
	
	@Autowired
	private IOwnerCustomDao ownerCustomDao;
	
	@Override
	public IBaseDao<OwnerCustomModel, OwnerCustom, String> getDao() {
		// TODO Auto-generated method stub
		return ownerCustomDao;
	}
	
	/**
	 * 功能:新增业主 <br/>
	 * 
	 * 重写：jiaokn <br/>
	 * 
	 * @Date ：2017年11月24日 下午3:39:19<br/>
	 * 
	 * @param ownerCustomModel
	 * @return <br/>
	 * @see com.yuju.common.core.service.AbstractBaseService#save(java.lang.Object)
	 */
	@Override
	public int save(OwnerCustomModel ownerCustomModel){
		ownerCustomModel.setId(Utils.getUUID());
		ownerCustomModel.setGmtCreate(new Date());
		ownerCustomModel.setGmtModified(new Date());
		return super.save(ownerCustomModel);
	}

	/**
	 * 功能:查询名称重复 <br/>
	 * 
	 * 重写：jiaokn <br/>
	 * 
	 * @Date ：2017年12月8日 下午3:40:57<br/>
	 * 
	 * @param ownerCustomModel
	 * @return <br/>
	 * @see com.yuju.group.service.IOwnerCustomService#validateName(com.yuju.group.model.OwnerCustomModel)
	 */
	@Override
	public boolean validateName(OwnerCustomModel ownerCustomModel) {
		boolean flag = false;
		if(ownerCustomModel.getId()==null){
			List<OwnerCustomModel> list = this.list(ownerCustomModel);
			if(list==null || list.size()==0){
				flag = true;
			}
		}else{
			OwnerCustomModel model = this.findById(ownerCustomModel.getId());
			if(ownerCustomModel.getName().equals(model.getName())){
				flag = true;
			}else{
				ownerCustomModel.setId(null);
				List<OwnerCustomModel> list = this.list(ownerCustomModel);
				if(list==null || list.size()==0){
					flag = true;
				}
			}
		}
		return flag;
	}

}
